<template>
  <div class="rule-list">
    <div class="rule-list-title">条件</div>
    <div class="rule-list-item" v-for="(item, index) in modelValue" :key="index">
      <div class="rule-list-label">{{ item.param }}</div>
      <div class="rule-list-relation">{{ set.get(item.param).relation }}</div>
      <div class="rule-list-content">
        <component :is="set.get(item.param).input" :disabled="!item.isUse" v-model="item.value" :="set.get(item.param).props" />
      </div>
      <div class="rule-list-switch">
        <ElSwitch v-model="item.isUse" :active-value="1" :inactive-value="0" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ElSwitch, ElInput, ElDatePicker } from 'element-plus'
import { OptionSelect }  from '@/components/form-item'

const map = new Map([
  ['入职日期', { param: '入职日期', value: '', isUse: 1 }],
  ['接待量', { param: '接待量', value: '', isUse: 1 }],
  ['转化率', { param: '转化率', value: '', isUse: 1 }],
  ['响应时间', { param: '响应时间', value: '', isUse: 1 }],
  ['答问比', { param: '答问比', value: '', isUse: 1 }],
  ['回复率', { param: '回复率', value: '', isUse: 1 }],
  ['正在服务店铺数', { param: '正在服务店铺数', value: '', isUse: 1 }],
  ['上月质检处罚数', { param: '上月质检处罚数', value: '', isUse: 1 }],
  ['近三个月店铺流失数量', { param: '近三个月店铺流失数量', value: '', isUse: 1 }],
  ['上月理论考试分数', { param: '上月理论考试分数', value: '', isUse: 1 }],
  ['上月迟到早退次数', { param: '上月迟到早退次数', value: '', isUse: 1 }],
  ['上月请假天数', { param: '上月请假天数', value: '', isUse: 1 }],
  ['上月旷工次数', { param: '上月旷工次数', value: '', isUse: 1 }],
  ['性别', { param: '性别', value: '', isUse: 1 }],
])

const set = new Map([
  ['入职日期', { relation: '大于', input: ElDatePicker, props: { format: "YYYY-MM-DD", valueFormat: "YYYY-MM-DD" } }],
  ['接待量', { relation: '小于', input: ElInput, props: {} }],
  ['转化率', { relation: '大于', input: ElInput, props: {} }],
  ['响应时间', { relation: '小于', input: ElInput, props: {} }],
  ['答问比', { relation: '大于', input: ElInput, props: {} }],
  ['回复率', { relation: '大于', input: ElInput, props: {} }],
  ['正在服务店铺数', { relation: '小于', input: ElInput, props: {} }],
  ['上月质检处罚数', { relation: '小于', input: ElInput, props: {} }],
  ['近三个月店铺流失数量', { relation: '小于', input: ElInput, props: {} }],
  ['上月理论考试分数', { relation: '大于', input: ElInput, props: {} }],
  ['上月迟到早退次数', { relation: '小于', input: ElInput, props: {} }],
  ['上月请假天数', { relation: '小于', input: ElInput, props: {} }],
  ['上月旷工次数', { relation: '小于', input: ElInput, props: {} }],
  ['性别', { relation: '等于', input: OptionSelect, props: { clearable: true, options: [{ label: '男', value: '男' }, { label: '女', value: '女' }] } }],
])

interface Props {
  modelValue: any[];
  data: object;
}

const props = withDefaults(defineProps<Props>(), {
  modelValue: () => [],
  data: () => ({})
})

interface Emits {
  'update:model-value': [any[]]
}
const emit = defineEmits<Readonly<Emits>>()

if (!props.modelValue || !props.modelValue.length) {
  emit('update:model-value', [...map.values()])
}
</script>

<style scoped lang="scss">
.rule-list {
  width: 100%;
  &-title {
    font-family: PingFangHK-Medium;
    font-weight: 500;
    font-size: 14px;
    color: #333333;
  }

  &-item {
    display: flex;
    align-items: center;
    margin-bottom: 14px;
  }

  &-label {
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 12px;
    color: #333333;
    width: 130px;
  }

  &-content {
    flex: 1;
  }

  &-switch {
    text-align: right;
    width: 60px;
  }

  &-relation {
    width: 40px;
    flex-shrink: 0;
  }
}
</style>
